var i = 1;
var music = document.getElementById("music")

function user() {
    document.getElementById("maoboli").className = "image__overlay image__overlay--blur_off"
    document.getElementById("admin").className = "BTN_MOSHI_OFF_style"
    document.getElementById("user").className = "BTN_MOSHI_ON_style"
    document.getElementById("T2").innerText = "生态健康生活视频网"
    document.getElementById("T3").innerText = "User-System"
    document.getElementById("register").hidden = false

    i = 1
}

function admin() {
    document.getElementById("maoboli").className = "image__overlay image__overlay--blur_on"
    document.getElementById("admin").className = "BTN_MOSHI_ON_style"
    document.getElementById("user").className = "BTN_MOSHI_OFF_style"
    document.getElementById("T2").innerText = "管理员登录"
    document.getElementById("T3").innerText = "Admin-System"
    document.getElementById("register").hidden = true

    i = 2
}

function login() {
    var code = document.getElementById("code").value
    var pwd = document.getElementById("pwd").value
    if (i == 1) {
        $.ajax({
            type: "post",
            url: "/user/login",
            data: {
                user_name: code,
                user_pwd: pwd,
            },
            async: false,
            success: function (response) {
                if (response == "error")
                    alert("登录失败")
                else if (response == "ok") {
                    setTimeout(window.location.href = "/html/user/main.html", 1000);
                } else {
                    alert("未知失败")
                }
            }
        });

    } else if (i == 2) {
        $.ajax({
            type: "post",
            url: "/admin/login",
            data: {
                admin_name: code,
                admin_pwd: pwd,
            },
            async: false,
            success: function (response) {
                if (response == "error")
                    alert("登录失败")
                else if (response == "ok") {

                    setTimeout(window.location.href = "/video/main", 1000);
                } else {
                    alert("未知失败")
                }
            }
        });
    }
}


function pwd_style() {
    var p_id = document.getElementById("pwd").type
    if (p_id == "password") {
        document.getElementById("pwd").type = "test"
    }
    if (p_id == "text") {
        document.getElementById("pwd").type = "password"

    }
}

function register(){
    setTimeout(window.location.href = "/html/user/register.html", 1000);
}
